package edu.hebeu.evil.freshmenguide.Activity;

import android.graphics.RectF;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import edu.hebeu.evil.freshmenguide.R;
import uk.co.senab.photoview.PhotoViewAttacher;

/****************************************************
 * com.aida.evil.eda.Answer.ImageZoom
 * 作者：白雨濃  evil
 * 时间：16-2-22 21:02
 * 邮箱：evilbai@foxmail.com
 * 页面用途：图片放大
 ****************************************************/
public class ImageZoom extends AppCompatActivity
{
    private PhotoViewAttacher photoViewAttacher;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.imagezoom);

        ImageView imageView = (ImageView) findViewById(R.id.imagezoom_imageView);

        String url = getIntent().getStringExtra("IMGURL");
        int res = getIntent().getIntExtra("IMGRES", 0);

        if (url != null)
            Glide.with(this).load(url).into(imageView);
        if (res != 0)
            Glide.with(this).load(res).into(imageView);

        photoViewAttacher = new PhotoViewAttacher(imageView);//将image置入到photoViewAttacher

        photoViewAttacher.setScaleType(ImageView.ScaleType.FIT_CENTER);//设置成适应到中心

        photoViewAttacher.setOnMatrixChangeListener(new PhotoViewAttacher.OnMatrixChangedListener()
        {
            @Override
            public void onMatrixChanged(RectF rectF)
            {
                //显示坐标
            }
        });

        photoViewAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener()
        {
            @Override
            public void onPhotoTap(View view, float x, float y)
            {
                //双击变化
                float xPercentage = x * 100f;
                float yPercentage = y * 100f;
            }
        });
    }

    @Override
    public void onBackPressed()
    {
        super.onBackPressed();
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        photoViewAttacher.cleanup();//使用后必须清除
    }
}
